<?php

namespace app\common\model;

use think\Model;


class LihuaOrderActivity extends Model
{

    // 表名
    protected $table = 'lihua_order_activity';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    //多订单商品列表，订单id为索引
    public static function ordersActList($order_sns = [])
    {
        $acts = [];
        if (is_array($order_sns)) {
            $actsList = self::whereIn('order_sn', $order_sns)->select();
            $s = self::getLastSql();
            foreach ($actsList as $k => $v) {
                $acts[$v['order_sn']][] = [
                    'id'          => $v['id'],
                    'type'        => $v['type'],
                    'activity_id' => $v['activity_id'],
                    'order_sn'    => $v['order_sn'],
                    'user_id'     => $v['user_id'],
                    'discount'    => round($v['discount'], 2),
                    'createtime'  => $v['createtime'],
                    'name'        => $v['name'],
                ];
            }
        }
        return $acts;
    }

}
